package com.mdinic.blogovi.ctrl;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.roo.addon.web.mvc.controller.converter.RooConversionService;

import com.mdinic.blogovi.model.Blog;
import com.mdinic.blogovi.model.BlogPost;
import com.mdinic.blogovi.model.BlogType;
import com.mdinic.blogovi.model.Comment;
import com.mdinic.blogovi.model.Email;
import com.mdinic.blogovi.model.Fav;
import com.mdinic.blogovi.model.Follow;
import com.mdinic.blogovi.model.Person;
import com.mdinic.blogovi.model.Promote;
import com.mdinic.blogovi.model.ReadShare;
import com.mdinic.blogovi.model.Share;
import com.mdinic.blogovi.model.Vote;

@Configurable
/**
 * A central place to register application converters and formatters. 
 */
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

    @Override
    protected void installFormatters(FormatterRegistry registry) {
        super.installFormatters(registry);
        // Register application converters and formatters
    }

    public Converter<BlogPost, String> getBlogPostToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.BlogPost, java.lang.String>() {
            @Override
            public String convert(BlogPost blogPost) {
                return new StringBuilder().append(blogPost.getUrl()).append(' ').append(blogPost.getThumb())
                        .append(' ').append(blogPost.getHeadline()).append(' ').append(blogPost.getDescription())
                        .toString();
            }
        };
    }

    public Converter<Long, BlogPost> getIdToBlogPostConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.BlogPost>() {
            @Override
            public com.mdinic.blogovi.model.BlogPost convert(java.lang.Long id) {
                return BlogPost.findBlogPost(id);
            }
        };
    }

    public Converter<String, BlogPost> getStringToBlogPostConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.BlogPost>() {
            @Override
            public com.mdinic.blogovi.model.BlogPost convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), BlogPost.class);
            }
        };
    }

    public Converter<BlogType, String> getBlogTypeToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.BlogType, java.lang.String>() {
            @Override
            public String convert(BlogType blogType) {
                return new StringBuilder().append(blogType.getName()).toString();
            }
        };
    }

    public Converter<Long, BlogType> getIdToBlogTypeConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.BlogType>() {
            @Override
            public com.mdinic.blogovi.model.BlogType convert(java.lang.Long id) {
                return BlogType.findBlogType(id);
            }
        };
    }

    public Converter<String, BlogType> getStringToBlogTypeConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.BlogType>() {
            @Override
            public com.mdinic.blogovi.model.BlogType convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), BlogType.class);
            }
        };
    }

    public Converter<Comment, String> getCommentToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Comment, java.lang.String>() {
            @Override
            public String convert(Comment comment) {
                return new StringBuilder().append(comment.getText()).toString();
            }
        };
    }

    public Converter<Long, Comment> getIdToCommentConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Comment>() {
            @Override
            public com.mdinic.blogovi.model.Comment convert(java.lang.Long id) {
                return Comment.findComment(id);
            }
        };
    }

    public Converter<String, Comment> getStringToCommentConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Comment>() {
            @Override
            public com.mdinic.blogovi.model.Comment convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Comment.class);
            }
        };
    }

    public Converter<Fav, String> getFavToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Fav, java.lang.String>() {
            @Override
            public String convert(Fav fav) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, Fav> getIdToFavConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Fav>() {
            @Override
            public com.mdinic.blogovi.model.Fav convert(java.lang.Long id) {
                return Fav.findFav(id);
            }
        };
    }

    public Converter<String, Fav> getStringToFavConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Fav>() {
            @Override
            public com.mdinic.blogovi.model.Fav convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Fav.class);
            }
        };
    }

    public Converter<Person, String> getPersonToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Person, java.lang.String>() {
            @Override
            public String convert(Person person) {
                return new StringBuilder().append(person.getFirstname()).append(' ').append(person.getJoined())
                        .append(' ').append(person.getBirthday()).append(' ').append(person.getWebsite()).toString();
            }
        };
    }

    public Converter<Long, Person> getIdToPersonConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Person>() {
            @Override
            public com.mdinic.blogovi.model.Person convert(java.lang.Long id) {
                return Person.findPerson(id);
            }
        };
    }

    public Converter<String, Person> getStringToPersonConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Person>() {
            @Override
            public com.mdinic.blogovi.model.Person convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Person.class);
            }
        };
    }

    public Converter<Vote, String> getVoteToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Vote, java.lang.String>() {
            @Override
            public String convert(Vote vote) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, Vote> getIdToVoteConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Vote>() {
            @Override
            public com.mdinic.blogovi.model.Vote convert(java.lang.Long id) {
                return Vote.findVote(id);
            }
        };
    }

    public Converter<String, Vote> getStringToVoteConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Vote>() {
            @Override
            public com.mdinic.blogovi.model.Vote convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Vote.class);
            }
        };
    }

    public Converter<Blog, String> getBlogToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Blog, java.lang.String>() {
            @Override
            public String convert(Blog blog) {
                return new StringBuilder().append(' ').append(blog.getUrl()).toString();
            }
        };
    }

    public Converter<Long, Blog> getIdToBlogConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Blog>() {
            @Override
            public com.mdinic.blogovi.model.Blog convert(java.lang.Long id) {
                return Blog.findBlog(id);
            }
        };
    }

    public Converter<String, Blog> getStringToBlogConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Blog>() {
            @Override
            public com.mdinic.blogovi.model.Blog convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Blog.class);
            }
        };
    }

    public Converter<Email, String> getEmailToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Email, java.lang.String>() {
            @Override
            public String convert(Email email) {
                return new StringBuilder().append(email.getName()).append(' ').append(email.getSubject()).append(' ')
                        .append(email.getBody()).toString();
            }
        };
    }

    public Converter<Long, Email> getIdToEmailConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Email>() {
            @Override
            public com.mdinic.blogovi.model.Email convert(java.lang.Long id) {
                return Email.findEmail(id);
            }
        };
    }

    public Converter<String, Email> getStringToEmailConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Email>() {
            @Override
            public com.mdinic.blogovi.model.Email convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Email.class);
            }
        };
    }

    public void installLabelConverters(FormatterRegistry registry) {
        registry.addConverter(getBlogPostToStringConverter());
        registry.addConverter(getIdToBlogPostConverter());
        registry.addConverter(getStringToBlogPostConverter());
        registry.addConverter(getBlogTypeToStringConverter());
        registry.addConverter(getIdToBlogTypeConverter());
        registry.addConverter(getStringToBlogTypeConverter());
        registry.addConverter(getCommentToStringConverter());
        registry.addConverter(getIdToCommentConverter());
        registry.addConverter(getStringToCommentConverter());
        registry.addConverter(getFavToStringConverter());
        registry.addConverter(getIdToFavConverter());
        registry.addConverter(getStringToFavConverter());
        registry.addConverter(getPersonToStringConverter());
        registry.addConverter(getIdToPersonConverter());
        registry.addConverter(getStringToPersonConverter());
        registry.addConverter(getVoteToStringConverter());
        registry.addConverter(getIdToVoteConverter());
        registry.addConverter(getStringToVoteConverter());

        registry.addConverter(getBlogToStringConverter());
        registry.addConverter(getIdToBlogConverter());
        registry.addConverter(getStringToBlogConverter());
    }

    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();
        installLabelConverters(getObject());
    }

    public Converter<Follow, String> getFollowToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Follow, java.lang.String>() {
            @Override
            public String convert(Follow follow) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, Follow> getIdToFollowConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Follow>() {
            @Override
            public com.mdinic.blogovi.model.Follow convert(java.lang.Long id) {
                return Follow.findFollow(id);
            }
        };
    }

    public Converter<String, Follow> getStringToFollowConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Follow>() {
            @Override
            public com.mdinic.blogovi.model.Follow convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Follow.class);
            }
        };
    }

    public Converter<ReadShare, String> getFollowReadToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.ReadShare, java.lang.String>() {
            @Override
            public String convert(ReadShare followRead) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, ReadShare> getIdToFollowReadConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.ReadShare>() {
            @Override
            public com.mdinic.blogovi.model.ReadShare convert(java.lang.Long id) {
                return ReadShare.findReadShare(id);
            }
        };
    }

    public Converter<String, ReadShare> getStringToFollowReadConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.ReadShare>() {
            @Override
            public com.mdinic.blogovi.model.ReadShare convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), ReadShare.class);
            }
        };
    }

    public Converter<Share, String> getFollowShareToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Share, java.lang.String>() {
            @Override
            public String convert(Share followShare) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, Share> getIdToFollowShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Share>() {
            @Override
            public com.mdinic.blogovi.model.Share convert(java.lang.Long id) {
                return Share.findShare(id);
            }
        };
    }

    public Converter<String, Share> getStringToFollowShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Share>() {
            @Override
            public com.mdinic.blogovi.model.Share convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Share.class);
            }
        };
    }

    public Converter<Share, String> getShareToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Share, java.lang.String>() {
            @Override
            public String convert(Share share) {
                return "(no displayable fields)";
            }
        };
    }

    public Converter<Long, Share> getIdToShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Share>() {
            @Override
            public com.mdinic.blogovi.model.Share convert(java.lang.Long id) {
                return Share.findShare(id);
            }
        };
    }

    public Converter<String, Share> getStringToShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Share>() {
            @Override
            public com.mdinic.blogovi.model.Share convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Share.class);
            }
        };
    }

	public Converter<ReadShare, String> getReadShareToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.ReadShare, java.lang.String>() {
            public String convert(ReadShare readShare) {
                return "(no displayable fields)";
            }
        };
    }

	public Converter<Long, ReadShare> getIdToReadShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.ReadShare>() {
            public com.mdinic.blogovi.model.ReadShare convert(java.lang.Long id) {
                return ReadShare.findReadShare(id);
            }
        };
    }

	public Converter<String, ReadShare> getStringToReadShareConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.ReadShare>() {
            public com.mdinic.blogovi.model.ReadShare convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), ReadShare.class);
            }
        };
    }

	public Converter<Promote, String> getPromoteToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.mdinic.blogovi.model.Promote, java.lang.String>() {
            public String convert(Promote promote) {
                return new StringBuilder().append(promote.getExpression()).toString();
            }
        };
    }

	public Converter<Long, Promote> getIdToPromoteConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Long, com.mdinic.blogovi.model.Promote>() {
            public com.mdinic.blogovi.model.Promote convert(java.lang.Long id) {
                return Promote.findPromote(id);
            }
        };
    }

	public Converter<String, Promote> getStringToPromoteConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, com.mdinic.blogovi.model.Promote>() {
            public com.mdinic.blogovi.model.Promote convert(String id) {
                return getObject().convert(getObject().convert(id, Long.class), Promote.class);
            }
        };
    }
}
